package com.example.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.springboot.entity.CheckRoom;
import com.example.springboot.entity.LeaveStu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CheckRoomMapper extends BaseMapper<CheckRoom> {
    @Select("SELECT a.*, b.*\n" +
            "FROM dorm_room a\n" +
            "         LEFT JOIN (\n" +
            "    SELECT dormroom_id, MAX(checktime) AS latest_checktime\n" +
            "    FROM checkroom\n" +
            "    GROUP BY dormroom_id\n" +
            ") AS latest_check ON a.dormroom_id = latest_check.dormroom_id\n" +
            "         LEFT JOIN checkroom b ON latest_check.dormroom_id = b.dormroom_id AND latest_check.latest_checktime = b.checktime where  IF(#{search} IS not NULL, a.dormroom_id = #{search}, 1=1)\n" +
            "ORDER BY a.dormroom_id")
    List<CheckRoom> findsql(String search, Integer pageNum, Integer pageSize);
    @Update("update checkroom set checksituation=#{checksituation},healthsituation=#{healthsituation},ydpeople=#{ydpeople},sdpeople=#{sdpeople}   where dormroom_id =#{dormroomid} ")
    int updateByStudentid(CheckRoom checkRoom);
    @Select("select count(1) from dorm_room a left join checkroom b on a.dormroom_id=b.dormroom_id where 1=1  LIKE CONCAT('%',#{search},'%') order by b.checktime desc ")
    int findcount(String search);
}
